fix(api): guard out-of-range numeric since on /api/pulls#234
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughIn ChangesDefensive epoch guard in parseSinceIso
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/app/api/pulls/route.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. Warning Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
64de80f to
e4cfca7
Compare
parseSinceIso took the numeric branch for any finite `since > 0` and called new Date(sinceMs).toISOString() without validating the result. A finite but out-of-range epoch (e.g. ?since=1e21 or a 20-digit integer) produces an Invalid Date, and Date.prototype.toISOString() throws RangeError on it, so the request crashed with an unhandled 500 instead of being treated as a malformed filter. Validate the millisecond date before formatting, mirroring the guard already applied to the date-string branch, so an out-of-range `since` falls through to null (no filter) like other malformed input.
c57ee02 to
8fbdc0b
Compare
Summary
/api/pulls?since=...could crash with an unhandledRangeErroron a malformedsincevalue.parseSinceIsotook the numeric branch for any finitesince > 0and callednew Date(sinceMs).toISOString()without validating the result. A finite but out-of-range epoch (e.g.?since=1e21, or a 20-digit integer) produces an Invalid Date, andDate.prototype.toISOString()throwsRangeError: Invalid time valueon it — so the route returned a 500 instead of treating it as a bad filter.The date-string branch right below already guards with
Number.isFinite(sinceDate.getTime()); this applies the same guard to the numeric branch, so an out-of-rangesincefalls through tonull(no filter), consistent with how other malformed input is handled.Related Issues
No issue; small input-robustness fix in the same vein as the existing malformed-input handling.
Type of Change
Testing
pnpm buildpassesRan from the repo root (Node 22, pnpm 10):
Reproduced the bug and confirmed the fix against the isolated
parseSinceIsologic:Checklist
Summary by CodeRabbit